<template>
	<view class="container">
		<view class="addBox flex-ac">
			<view class="inputBox flex-ac">
				<image src="../../../static/img/ss.png" mode=""></image>
				<input v-model="form.carNo" type="text" placeholder="请输入车牌号" />
			</view>
			<view class="btn-search" @click="search">查询</view>
		</view>
		<view class="carList">
			<view class="item" v-for="(item,index) in list" :key="index" @click.stop="selCar(index)">
				<image class="icon-car" src="../../../static/img/car.png" mode="aspectFill"></image>
				<view class="cell flex-ac">
					<view style="font-size: 30rpx;">{{item.carNo || ''}}/{{getDictName(item.carType)}} </view>
					<view class="label" v-if='item.type == 1'>自有车辆</view>
					<view class="label2" v-if='item.type == 2'>外调车辆</view>
				</view>
				<view class="cell flex-ac" style="margin-top: 20rpx;">
					<view>{{item.driverName || ''}}-{{item.driverPhone || ''}}</view>
					<view class="setDr" @click.stop="setDriver(index)">设置司机 ></view>
				</view>
				<view class="cell flex-ac">
					<view v-if="item.status == 1">状态：空闲</view>
					<view v-if="item.status == 2">状态：运输中</view>
					<view v-if="item.status == 3">状态：休假</view>
					<view v-if="item.status == 4">状态：维修</view>
				</view>
				<view class="cell flex-ac">
					<view>空闲时间：{{item.idleTime || ''}}</view>
				</view>
				
			</view>
		</view>
		<!-- <view class="foot">
			<view class="btnBox flex-ac">
				<view class="btn-1 middle" @click="submit">确定</view>
			</view>
			<x-botSpace></x-botSpace>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				list: '',
				form:{
					carNo: '',
					current: 1,
					size: 10
				},
				dict: [],
				isNext: true
			}
		},
		onLoad(opt) {
			if(opt) console.log('opt:', opt)
			this.id = opt.id
			// this.getCarList()
			this.getDict()
		},
		onReachBottom() {
			this.form.current++
			this.getCarList()
		},
		methods: {
			submit(){
				let arr = this.list.filter(item=>item.sel)
				if(arr.length == 0){
					this.$Toast.message('请选择车辆')
					return
				}else{
					var isAllDriver = true
					arr.map(el=>{
						if(!el.driverId){
							isAllDriver = false
							console.log('请完善车辆司机信息')
						}
					})
					if(!isAllDriver){
						this.$Toast.message('请完善车辆司机信息')
						return
					}
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2]
					prevPage.$vm.getData(arr)
					this.$Jump.Back(1)
				}
			},
			search(){
				this.form.current = 1
				this.getCarList()
			},
			selCar(index){
				this.list[index].sel = !this.list[index].sel
			},
			setDriver(index){
				this.$Jump.Open('/pages/index/selDriver/selDriver?index=' + index)
			},
			getCarList(){
				if(!this.isNext) return
				this.isNext = false
				this.$Net.get('/car/page', this.form).then(res=>{
					console.log('车辆列表：', res)
					if(res.data.length > 0){
						res.data.map(el=>{
							el.sel = false
						})
					}
					if(this.form.current == 1){
						this.list = res.data
					}else{
						this.list = this.list.concat(res.data)
					}
					this.isNext = true
				})
			},
			getDictName(id){
				return this.dict.find(item=>item.code == id).name || ''
			},
			// 获取字典数据
			getDict(){
				this.$Net.get('/sysDict/code/car_type').then(res=>{
					console.log('字典数据:', res)
					this.dict = res.data
					this.getCarList()
				})
			},
		
		}
	}
</script>

<style lang="scss">
	page{ background-color: #fff; }
</style>

<style lang="scss" scoped>
	// @import './style.scss';
	.carList{
		width: 100%;
		padding-top: 100rpx;
		padding-bottom: 150rpx;
		.item{
			position: relative;
			padding: 28rpx;
			padding-left: 90rpx;
			width: 100%;
			border-bottom: 1rpx solid #f7f7f7;
			font-size: 24rpx;
			.icon-car{
				width: 50rpx;
				height: 50rpx;
				position: absolute;
				top: 30rpx;
				left: 25rpx;
			}
			.shanchuBox{
				padding: 40rpx;
				position: absolute;
				right: 10rpx;
				top: 50%;
				transform: translateY(-50%);
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
			.cell{
				margin-bottom: 8rpx;
				.setDr{
					margin-left: 20rpx;
					color: #1684FC;
					font-size: 24rpx;
					text-decoration: underline;
				}
			}
			.label{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #f2f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
			.label2{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #a1f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
		}
	}
	.addBox{
		width: 100%;
		height: 100rpx;
		padding-left: 30rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #f7f7f7;
		background-color: #ffffff;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
		.inputBox{
			flex: 1;
			height: 70rpx;
			border-radius: 40rpx;
			background-color: #f7f7f7;
			padding: 0 20rpx;
			input{
				flex: 1;
				color: #333;
			}
		}
		.btn-search{
			height: 100rpx;
			line-height: 100rpx;
			padding: 0 30rpx;
			color: #1F82FE;
		}
		image{
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}
	.foot {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 30rpx;
	
		.btnBox {
			width: 100%;
	
			.btn-1 {
				flex: 1;
				height: 90rpx;
				background: #1684FC;
				border-radius: 10rpx;
				color: #ffffff;
				font-size: 34rpx;
			}
	
			.btn-2 {
				flex: 1;
				height: 90rpx;
				border: 1px solid #1684FC;
				border-radius: 10rpx;
				color: #1684FC;
				font-size: 34rpx;
			}
		}
	}
</style>
